<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登陆</title>
</head>
<body>

<div style="width: 200px;margin: 50px auto">
    <div id="qrcode"></div>
    <div id="msg" style="display: none">
        扫码成功!
    </div>
</div>

<script type='text/javascript' src='https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js'></script>
<script src="https://cdn.bootcss.com/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
<script>
    $(function () {
        let count = 0;
        //获取二维码参数
        $.get('https://34i33045l8.oicp.vip/weChat/getQrCode', function (res) {
            //生成二维码
            $('#qrcode').qrcode(res.url);

            //轮训获取用户扫码登陆状态
            let task = setInterval(function () {
                // if (count  >= 60) {
                //     clearInterval(task)
                //     $('#qrcode').html("登陆超时，请重新登陆扫码")
                // }
                let url = "https://34i33045l8.oicp.vip/weChat/checkLogin";
                $.post(url, {ticket: res.ticket}, function ({code, msg}) {
                    console.log(code);
                    if (code === 200) { // 扫码并且关注成功
                        clearInterval(task)
                        location.href = 'https://yby6.com'
                    } else if (code === 201) { // 扫码成功
                        $("#msg").text(msg);
                        document.querySelector("#msg").style.display = "block"
                        document.querySelector("#msg").style.color = "red"
                    }
                    count++;
                })
            }, 10000)
        })
    })

</script>
</body>
</html>